const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')
const path = require('path')
const CompressionWebpackPlugin = require('compression-webpack-plugin')

const mode = process.env
let targetPath = ''
switch (mode.ENVIRONMENT) {
  case 'Development':
    // targetPath = 'http://192.168.10.88:11000' // 李祥峰
    // targetPath = 'http://192.168.10.167:11000' // 彪哥
    // targetPath = 'http://192.168.10.110:5000'    // 110:5000
    targetPath = 'http://192.168.10.167:15000' // 167:15000
    // targetPath = 'http://192.168.10.21:15000' // hh
    // targetPath = 'http://192.168.10.37:15000' // G
    break
  case 'UserAcceptanceTest':
    targetPath = 'http://192.168.10.31:3001' // 测试
    break
  case 'Production':
    targetPath = 'https://jihehao.yilianyun.top'
    break
}
module.exports = defineConfig({
  publicPath: './',

  transpileDependencies: true,
  lintOnSave: false,

  chainWebpack: (config) => {
    config.resolve.alias.set('@', path.join(__dirname, './src'))
    config.resolve.alias.set('@a', path.join(__dirname, './src/assets'))
  },

  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        PROCESS_ENV: JSON.stringify(mode),
      }),
      new CompressionWebpackPlugin({
        test: /\.js$|\.html$|\.css$/,
        threshold: 4096,
      }),
    ],
    devtool: "source-map",
    // optimization: {
    //   runtimeChunk: 'single',
    //   splitChunks: {
    //     chunks: 'all',
    //     maxInitialRequests: Infinity,
    //     minSize: 20000,
    //     maxSize: 60000,
    //     cacheGroups: {
    //       vendors: {
    //         test: /[\\/]node_modules[\\/]/,
    //         priority: -10,
    //         name(module) {
    //           const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
    //           return `npm.${packageName.replace('@', '')}`
    //         },
    //       },
    //     },
    //   }
    // }
  },

  devServer: {
    open: true,
    client: {
      overlay: false,
    },
    proxy: {
      '/ums': {
        target: targetPath,
        changeOrigin: true,
      },
      '/eas': {
        target: targetPath,
        changeOrigin: true,
      },
      '/mnc': {
        target: targetPath,
        changeOrigin: true,
      },
    },
  },
})
